package edu.pitt.cs.cs2510.project3.model;

import edu.pitt.cs.cs2510.project3.configuration.InputParameters;

public class TestFrontEnd extends FrontEnd {

	public TestFrontEnd(int id, InputParameters simulationParameters, Object monitor) {
		super(id, simulationParameters, monitor);
		
		int i = 0;
		for (File file : this.files.values()) {
			file.master=true;
			this.workers.add(new WorkerServer(i, simulationParameters, this, this));
			this.workers.get(i).files.put(file.fileId, file);
			this.workers.get(i).start();
			i++;
		}
	}

	@Override
	protected void handleMessage(Message message) {
		super.handleMessage(message);
	}

	@Override
	protected void handleRequest(Request request) {
		
		/*for (WorkerServer workerServer : this.workers)
		{
			if (workerServer.hasFileBlock(request.fileId, request.currentBlockId))
			{
				workerServer.requests.add(request);
			}
		}*/
		super.handleRequest(request);
	}

	@Override
	protected void runAlgorithm() {
		super.runAlgorithm();
	}
	
	@Override
	public boolean isDone() {
		return super.isDone();
	}

	@Override
	public String toString() {
		return "TestFrontEnd [workers=" + workers /*+ ", messages=" + messages*/
				+ ", completedMessages=" + completedMessages + ", id=" + id
				+ ", files=" + files + ", requests=" + requests
				+ ", completedRequests=" + completedRequests
				+ ", replications=" + replications + ", time=" + time
				+ ", die=" + die + ", tick=" + tick + ", noMoreRequests="
				+ noMoreRequests + ", requestedFilenames=" + requestedFilenames
				+ "]";
	}

	@Override
	protected WorkerServer getReplicationTarget(Request request, String source) {
		// TODO Auto-generated method stub
		return null;
	}
}
